VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form frmDetailsData 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Details"
   ClientHeight    =   8070
   ClientLeft      =   45
   ClientTop       =   315
   ClientWidth     =   6570
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8070
   ScaleWidth      =   6570
   ShowInTaskbar   =   0   'False
   Begin InetCtlsObjects.Inet Inet1 
      Left            =   1200
      Top             =   7440
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
   Begin VB.CommandButton cmdSubmit 
      Caption         =   "Add this customer"
      Height          =   495
      Left            =   4200
      TabIndex        =   1
      Top             =   7440
      Width           =   2175
   End
   Begin VB.TextBox txtXML 
      Appearance      =   0  'Flat
      Height          =   7215
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   120
      Width           =   6255
   End
End
Attribute VB_Name = "frmDetailsData"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Sub cmdSubmit_Click()
    CustomerType = NEW_CUS_YP
    Unload customer
    Load customer
    FillInWithGrab
    customer.Show
    ReInitData
    txtXML.Text = ""
End Sub

Private Sub ReInitData()
    If yp.ADDRESS <> "" Then
        customer.Text1(1).Text = yp.ADDRESS
    End If
    
    If yp.des <> "" Then
        customer.Text1(7).Text = yp.des
    End If
    
    If yp.email <> "" Then
        customer.Text1(9).Text = yp.email
    End If
    
    If yp.fax <> "" Then
        customer.Text1(2).Text = yp.fax
    End If
    
    If yp.HRS <> "" Then
        customer.UpdateTradingHrsFields yp.HRS
        'customer.ckHrs.Value = 1
        'customer.txtTime.Text = yp.HRS
    End If
    
    If yp.logo <> "" Then
        customer.Text1(8).Text = Trim(str(customer.temp_userid)) & ".jpg"
    End If
    
    If yp.NAME <> "" Then
        customer.Text1(13).Text = yp.NAME
    End If
    
    If yp.SLOGAN <> "" Then
        customer.Text1(6).Text = yp.SLOGAN
    End If
    
    If yp.tel <> "" Then
        customer.Text1(10).Text = yp.tel
    End If
    
    If yp.website <> "" Then
        customer.Text1(3).Text = yp.website
    End If
    
    'the first step will go to SA directly
    '
    customer.cmbCity.ListIndex = 4
End Sub

Private Sub FillInWithGrab()
    ParseXML
End Sub

Private Sub clrStructure()
    yp.ADDRESS = ""
    yp.BRAND_P = ""
    yp.des = ""
    yp.email = ""
    yp.fax = ""
    yp.HRS = ""
    yp.logo = ""
    yp.NAME = ""
    yp.SLOGAN = ""
    yp.tel = ""
    yp.URL = ""
    yp.website = ""
End Sub

Private Sub ParseXML()
    Dim iTagLen As Integer
    Dim iBegin, iEnd As Long
    Dim iIndex As Long
    Dim sXML As String
    sXML = Trim(txtXML.Text)
    clrStructure
    If sXML = "" Then
        MsgBox "Hi! It's empty!", vbOKOnly, SOFT_TITLE
        Exit Sub
    End If
    
    iBegin = 0
    iEnd = 0
    iIndex = 0
    '-------url--------------
    iIndex = InStr(1, sXML, "<URL>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</URL>")
        If iEnd > iBegin Then
            iTagLen = Len("<URL>")
            yp.URL = Mid(sXML, iBegin + Len("<URL>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------name--------------
    iIndex = InStr(1, sXML, "<Name>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Name>")
        If iEnd > iBegin Then
            iTagLen = Len("<Name>")
            yp.NAME = Mid(sXML, iBegin + Len("<Name>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Add--------------
    iIndex = InStr(1, sXML, "<Add>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Add>")
        If iEnd > iBegin Then
            iTagLen = Len("<Add>")
            yp.ADDRESS = Mid(sXML, iBegin + Len("<Add>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Brand--------------
    iIndex = InStr(1, sXML, "<Brand>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Brand>")
        If iEnd > iBegin Then
            iTagLen = Len("<Brand>")
            yp.BRAND_P = Mid(sXML, iBegin + Len("<Brand>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Des--------------
    iIndex = InStr(1, sXML, "<Des>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Des>")
        If iEnd > iBegin Then
            iTagLen = Len("<Des>")
            yp.des = Mid(sXML, iBegin + Len("<Des>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Email--------------
    iIndex = InStr(1, sXML, "<Email>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Email>")
        If iEnd > iBegin Then
            iTagLen = Len("<Email>")
            yp.email = Mid(sXML, iBegin + Len("<Email>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Fax--------------
    iIndex = InStr(1, sXML, "<Fax>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Fax>")
        If iEnd > iBegin Then
            iTagLen = Len("<Fax>")
            yp.fax = Mid(sXML, iBegin + Len("<Fax>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Hrs--------------
    iIndex = InStr(1, sXML, "<Hrs>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Hrs>")
        If iEnd > iBegin Then
            iTagLen = Len("<Hrs>")
            yp.HRS = Mid(sXML, iBegin + Len("<Hrs>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Logo--------------
    iIndex = InStr(1, sXML, "<Logo>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Logo>")
        If iEnd > iBegin Then
            iTagLen = Len("<Logo>")
            yp.logo = Mid(sXML, iBegin + Len("<Logo>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Slogan--------------
    iIndex = InStr(1, sXML, "<Slogan>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Slogan>")
        If iEnd > iBegin Then
            iTagLen = Len("<Slogan>")
            yp.SLOGAN = Mid(sXML, iBegin + Len("<Slogan>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Tel--------------
    iIndex = InStr(1, sXML, "<Tel>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Tel>")
        If iEnd > iBegin Then
            iTagLen = Len("<Tel>")
            yp.tel = Mid(sXML, iBegin + Len("<Tel>"), iEnd - iBegin - iTagLen)
        End If
    End If
    '-------Website--------------
    iIndex = InStr(1, sXML, "<Website>")
    iBegin = iIndex
    If iBegin <> 0 Then
        iEnd = InStr(iIndex, sXML, "</Website>")
        If iEnd > iBegin Then
            iTagLen = Len("<Website>")
            yp.website = Mid(sXML, iBegin + Len("<Website>"), iEnd - iBegin - iTagLen)
        End If
    End If
End Sub

Private Sub Form_Load()
    frmDetailsData.Height = frmInputURL.Height
    frmDetailsData.Top = frmInputURL.Top
    frmDetailsData.Width = frmInputURL.Width
    frmDetailsData.Left = frmInputURL.Left + frmInputURL.Width + 50
    txtXML.Width = frmDetailsData.Width - 600
    cmdSubmit.Left = txtXML.Left + txtXML.Width - cmdSubmit.Width
End Sub


Function downFile(Inet1 As Inet, URL As String, dest As String) As Boolean
On Error GoTo er1
        Dim bytes() As Byte
        bytes() = Inet1.OpenURL(URL, icByteArray)
        Dim tempS
        Open dest For Binary Access Write As #2
                Put #2, , bytes()
        Close #2
        downFile = True
        Exit Function
er1:
MsgBox Err.Description
downFile = False
End Function

Public Function DownloadPics(ByVal temp_id As String, ByVal full_id As String, ByVal slogo As String, ByVal sbrand As String)
    Dim sFolderPath As String
    sFolderPath = App.Path & "/" & full_id
    If Dir(sFolderPath, vbDirectory) = "" Then
        MkDir (sFolderPath)
    End If
    
    If slogo <> "" Then
        downFile Inet1, slogo, sFolderPath & "/" & temp_id & ".jpg"
    End If
    
    If sbrand <> "" Then
        downFile Inet1, sbrand, sFolderPath & "/brand.jpg"
    End If
End Function
